namespace PMS.BLL
{
    using PMS.DBUtility;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using System.Text;

    public class OrganReportBLL
    {
        public List<OrganReport> GetList(string organIDString, string where = "")
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("SELECT * ");
            builder.Append("  from view_OrganReport ");
            builder.Append(" where OrganID in(");
            builder.Append(organIDString);
            builder.Append(")");
            if (where != "")
            {
                builder.Append(where);
            }
            OrganReport item = null;
            DataSet set = DBHelper.Query(builder.ToString(), (SqlParameter[]) null);
            List<OrganReport> list = new List<OrganReport>();
            if (set.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in set.Tables[0].Rows)
                {
                    item = new OrganReport {
                        OrganName = row["OrganName"].ToString()
                    };
                    if (row["IsDoublePosition_Count"].ToString() != "")
                    {
                        item.IsDoublePosition_Count = int.Parse(row["IsDoublePosition_Count"].ToString());
                    }
                    if (row["OrganID"].ToString() != "")
                    {
                        item.OrganID = int.Parse(row["OrganID"].ToString());
                    }
                    if (row["User_Count"].ToString() != "")
                    {
                        item.User_Count = int.Parse(row["User_Count"].ToString());
                    }
                    if (row["Leader_Count"].ToString() != "")
                    {
                        item.Leader_Count = int.Parse(row["Leader_Count"].ToString());
                    }
                    if (row["UnLeader_Count"].ToString() != "")
                    {
                        item.UnLeader_Count = int.Parse(row["UnLeader_Count"].ToString());
                    }
                    if (row["ZTJ_Count"].ToString() != "")
                    {
                        item.ZTJ_Count = int.Parse(row["ZTJ_Count"].ToString());
                    }
                    if (row["FTJ_Count"].ToString() != "")
                    {
                        item.FTJ_Count = int.Parse(row["FTJ_Count"].ToString());
                    }
                    if (row["ZXJ_Count"].ToString() != "")
                    {
                        item.ZXJ_Count = int.Parse(row["ZXJ_Count"].ToString());
                    }
                    if (row["FXJ_Count"].ToString() != "")
                    {
                        item.FXJ_Count = int.Parse(row["FXJ_Count"].ToString());
                    }
                    if (row["ZKJ_Count"].ToString() != "")
                    {
                        item.ZKJ_Count = int.Parse(row["ZKJ_Count"].ToString());
                    }
                    if (row["IsOffice"].ToString() != "")
                    {
                        item.IsOffice = int.Parse(row["IsOffice"].ToString());
                    }
                    if (row["FKJ_Count"].ToString() != "")
                    {
                        item.FKJ_Count = int.Parse(row["FKJ_Count"].ToString());
                    }
                    if (row["ZGJ_Count"].ToString() != "")
                    {
                        item.ZGJ_Count = int.Parse(row["ZGJ_Count"].ToString());
                    }
                    if (row["FGJ_Count"].ToString() != "")
                    {
                        item.FGJ_Count = int.Parse(row["FGJ_Count"].ToString());
                    }
                    if (row["XSY_Count"].ToString() != "")
                    {
                        item.XSY_Count = int.Parse(row["XSY_Count"].ToString());
                    }
                    if (row["FXSY_Count"].ToString() != "")
                    {
                        item.FXSY_Count = int.Parse(row["FXSY_Count"].ToString());
                    }
                    if (row["DYY_Count"].ToString() != "")
                    {
                        item.DYY_Count = int.Parse(row["DYY_Count"].ToString());
                    }
                    if (row["FDYY_Count"].ToString() != "")
                    {
                        item.FDYY_Count = int.Parse(row["FDYY_Count"].ToString());
                    }
                    if (row["ZRKY_Count"].ToString() != "")
                    {
                        item.ZRKY_Count = int.Parse(row["ZRKY_Count"].ToString());
                    }
                    if (row["FZRKY_Count"].ToString() != "")
                    {
                        item.FZRKY_Count = int.Parse(row["FZRKY_Count"].ToString());
                    }
                    if (row["KY_Count"].ToString() != "")
                    {
                        item.KY_Count = int.Parse(row["KY_Count"].ToString());
                    }
                    item.PayWay = row["PayWay"].ToString();
                    if (row["BSY_Count"].ToString() != "")
                    {
                        item.BSY_Count = int.Parse(row["BSY_Count"].ToString());
                    }
                    if (row["BDJ_Count"].ToString() != "")
                    {
                        item.BDJ_Count = int.Parse(row["BDJ_Count"].ToString());
                    }
                    if (row["M_Count"].ToString() != "")
                    {
                        item.M_Count = int.Parse(row["M_Count"].ToString());
                    }
                    if (row["S_Count"].ToString() != "")
                    {
                        item.S_Count = int.Parse(row["S_Count"].ToString());
                    }
                    if (row["W_Count"].ToString() != "")
                    {
                        item.W_Count = int.Parse(row["W_Count"].ToString());
                    }
                    if (row["M_ZTJ_Count"].ToString() != "")
                    {
                        item.M_ZTJ_Count = int.Parse(row["M_ZTJ_Count"].ToString());
                    }
                    if (row["M_FTJ_Count"].ToString() != "")
                    {
                        item.M_FTJ_Count = int.Parse(row["M_FTJ_Count"].ToString());
                    }
                    if (row["M_ZXJ_Count"].ToString() != "")
                    {
                        item.M_ZXJ_Count = int.Parse(row["M_ZXJ_Count"].ToString());
                    }
                    if (row["M_FXJ_Count"].ToString() != "")
                    {
                        item.M_FXJ_Count = int.Parse(row["M_FXJ_Count"].ToString());
                    }
                    if (row["M_ZKJ_Count"].ToString() != "")
                    {
                        item.M_ZKJ_Count = int.Parse(row["M_ZKJ_Count"].ToString());
                    }
                    item.LevelName = row["LevelName"].ToString();
                    if (row["M_FKJ_Count"].ToString() != "")
                    {
                        item.M_FKJ_Count = int.Parse(row["M_FKJ_Count"].ToString());
                    }
                    if (row["M_KY_Count"].ToString() != "")
                    {
                        item.M_KY_Count = int.Parse(row["M_KY_Count"].ToString());
                    }
                    if (row["M_BSY_Count"].ToString() != "")
                    {
                        item.M_BSY_Count = int.Parse(row["M_BSY_Count"].ToString());
                    }
                    if (row["M_3"].ToString() != "")
                    {
                        item.M_3 = int.Parse(row["M_3"].ToString());
                    }
                    if (row["M_4"].ToString() != "")
                    {
                        item.M_4 = int.Parse(row["M_4"].ToString());
                    }
                    if (row["M_5"].ToString() != "")
                    {
                        item.M_5 = int.Parse(row["M_5"].ToString());
                    }
                    if (row["M_6"].ToString() != "")
                    {
                        item.M_6 = int.Parse(row["M_6"].ToString());
                    }
                    if (row["M_7"].ToString() != "")
                    {
                        item.M_7 = int.Parse(row["M_7"].ToString());
                    }
                    if (row["M_8"].ToString() != "")
                    {
                        item.M_8 = int.Parse(row["M_8"].ToString());
                    }
                    if (row["M_9"].ToString() != "")
                    {
                        item.M_9 = int.Parse(row["M_9"].ToString());
                    }
                    if (row["UserBuild_Count"].ToString() != "")
                    {
                        item.UserBuild_Count = int.Parse(row["UserBuild_Count"].ToString());
                    }
                    if (row["M_10"].ToString() != "")
                    {
                        item.M_10 = int.Parse(row["M_10"].ToString());
                    }
                    if (row["S_ZGJ_Count"].ToString() != "")
                    {
                        item.S_ZGJ_Count = int.Parse(row["S_ZGJ_Count"].ToString());
                    }
                    if (row["S_FGJ_Count"].ToString() != "")
                    {
                        item.S_FGJ_Count = int.Parse(row["S_FGJ_Count"].ToString());
                    }
                    if (row["S_ZJ_Count"].ToString() != "")
                    {
                        item.S_ZJ_Count = int.Parse(row["S_ZJ_Count"].ToString());
                    }
                    if (row["S_CJ_Count"].ToString() != "")
                    {
                        item.S_CJ_Count = int.Parse(row["S_CJ_Count"].ToString());
                    }
                    if (row["S_1"].ToString() != "")
                    {
                        item.S_1 = int.Parse(row["S_1"].ToString());
                    }
                    if (row["S_2"].ToString() != "")
                    {
                        item.S_2 = int.Parse(row["S_2"].ToString());
                    }
                    if (row["S_3"].ToString() != "")
                    {
                        item.S_3 = int.Parse(row["S_3"].ToString());
                    }
                    if (row["S_4"].ToString() != "")
                    {
                        item.S_4 = int.Parse(row["S_4"].ToString());
                    }
                    if (row["S_5"].ToString() != "")
                    {
                        item.S_5 = int.Parse(row["S_5"].ToString());
                    }
                    if (row["UserJobPostion_Count"].ToString() != "")
                    {
                        item.UserJobPostion_Count = int.Parse(row["UserJobPostion_Count"].ToString());
                    }
                    if (row["S_6"].ToString() != "")
                    {
                        item.S_6 = int.Parse(row["S_6"].ToString());
                    }
                    if (row["S_7"].ToString() != "")
                    {
                        item.S_7 = int.Parse(row["S_7"].ToString());
                    }
                    if (row["S_8"].ToString() != "")
                    {
                        item.S_8 = int.Parse(row["S_8"].ToString());
                    }
                    if (row["S_9"].ToString() != "")
                    {
                        item.S_9 = int.Parse(row["S_9"].ToString());
                    }
                    if (row["S_10"].ToString() != "")
                    {
                        item.S_10 = int.Parse(row["S_10"].ToString());
                    }
                    if (row["S_11"].ToString() != "")
                    {
                        item.S_11 = int.Parse(row["S_11"].ToString());
                    }
                    if (row["S_12"].ToString() != "")
                    {
                        item.S_12 = int.Parse(row["S_12"].ToString());
                    }
                    if (row["S_13"].ToString() != "")
                    {
                        item.S_13 = int.Parse(row["S_13"].ToString());
                    }
                    if (row["W_GJJS_Count"].ToString() != "")
                    {
                        item.W_GJJS_Count = int.Parse(row["W_GJJS_Count"].ToString());
                    }
                    if (row["W_JS_Count"].ToString() != "")
                    {
                        item.W_JS_Count = int.Parse(row["W_JS_Count"].ToString());
                    }
                    if (row["Manager_Count"].ToString() != "")
                    {
                        item.Manager_Count = int.Parse(row["Manager_Count"].ToString());
                    }
                    if (row["W_GJG_Count"].ToString() != "")
                    {
                        item.W_GJG_Count = int.Parse(row["W_GJG_Count"].ToString());
                    }
                    if (row["W_ZJG_Count"].ToString() != "")
                    {
                        item.W_ZJG_Count = int.Parse(row["W_ZJG_Count"].ToString());
                    }
                    if (row["W_CJG_Count"].ToString() != "")
                    {
                        item.W_CJG_Count = int.Parse(row["W_CJG_Count"].ToString());
                    }
                    if (row["W_PTG_Count"].ToString() != "")
                    {
                        item.W_PTG_Count = int.Parse(row["W_PTG_Count"].ToString());
                    }
                    if (row["W_0"].ToString() != "")
                    {
                        item.W_0 = int.Parse(row["W_0"].ToString());
                    }
                    if (row["W_1"].ToString() != "")
                    {
                        item.W_1 = int.Parse(row["W_1"].ToString());
                    }
                    if (row["W_2"].ToString() != "")
                    {
                        item.W_2 = int.Parse(row["W_2"].ToString());
                    }
                    if (row["W_3"].ToString() != "")
                    {
                        item.W_3 = int.Parse(row["W_3"].ToString());
                    }
                    if (row["W_4"].ToString() != "")
                    {
                        item.W_4 = int.Parse(row["W_4"].ToString());
                    }
                    if (row["W_5"].ToString() != "")
                    {
                        item.W_5 = int.Parse(row["W_5"].ToString());
                    }
                    if (row["Skiller_Count"].ToString() != "")
                    {
                        item.Skiller_Count = int.Parse(row["Skiller_Count"].ToString());
                    }
                    item.Remark = row["Remark"].ToString();
                    if (row["Worker_Count"].ToString() != "")
                    {
                        item.Worker_Count = int.Parse(row["Worker_Count"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public OrganReport GetModel(int organID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("SELECT * ");
            builder.Append("  from view_OrganReport ");
            builder.Append(" where OrganID=@OrganID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@OrganID", organID) };
            OrganReport report = new OrganReport();
            DataSet set = DBHelper.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                DataRow row = set.Tables[0].Rows[0];
                report.OrganName = row["OrganName"].ToString();
                if (row["IsDoublePosition_Count"].ToString() != "")
                {
                    report.IsDoublePosition_Count = int.Parse(row["IsDoublePosition_Count"].ToString());
                }
                if (row["OrganID"].ToString() != "")
                {
                    report.OrganID = int.Parse(row["OrganID"].ToString());
                }
                if (row["User_Count"].ToString() != "")
                {
                    report.User_Count = int.Parse(row["User_Count"].ToString());
                }
                if (row["Leader_Count"].ToString() != "")
                {
                    report.Leader_Count = int.Parse(row["Leader_Count"].ToString());
                }
                if (row["UnLeader_Count"].ToString() != "")
                {
                    report.UnLeader_Count = int.Parse(row["UnLeader_Count"].ToString());
                }
                if (row["ZTJ_Count"].ToString() != "")
                {
                    report.ZTJ_Count = int.Parse(row["ZTJ_Count"].ToString());
                }
                if (row["FTJ_Count"].ToString() != "")
                {
                    report.FTJ_Count = int.Parse(row["FTJ_Count"].ToString());
                }
                if (row["ZXJ_Count"].ToString() != "")
                {
                    report.ZXJ_Count = int.Parse(row["ZXJ_Count"].ToString());
                }
                if (row["FXJ_Count"].ToString() != "")
                {
                    report.FXJ_Count = int.Parse(row["FXJ_Count"].ToString());
                }
                if (row["ZKJ_Count"].ToString() != "")
                {
                    report.ZKJ_Count = int.Parse(row["ZKJ_Count"].ToString());
                }
                if (row["IsOffice"].ToString() != "")
                {
                    report.IsOffice = int.Parse(row["IsOffice"].ToString());
                }
                if (row["FKJ_Count"].ToString() != "")
                {
                    report.FKJ_Count = int.Parse(row["FKJ_Count"].ToString());
                }
                if (row["ZGJ_Count"].ToString() != "")
                {
                    report.ZGJ_Count = int.Parse(row["ZGJ_Count"].ToString());
                }
                if (row["FGJ_Count"].ToString() != "")
                {
                    report.FGJ_Count = int.Parse(row["FGJ_Count"].ToString());
                }
                if (row["XSY_Count"].ToString() != "")
                {
                    report.XSY_Count = int.Parse(row["XSY_Count"].ToString());
                }
                if (row["FXSY_Count"].ToString() != "")
                {
                    report.FXSY_Count = int.Parse(row["FXSY_Count"].ToString());
                }
                if (row["DYY_Count"].ToString() != "")
                {
                    report.DYY_Count = int.Parse(row["DYY_Count"].ToString());
                }
                if (row["FDYY_Count"].ToString() != "")
                {
                    report.FDYY_Count = int.Parse(row["FDYY_Count"].ToString());
                }
                if (row["ZRKY_Count"].ToString() != "")
                {
                    report.ZRKY_Count = int.Parse(row["ZRKY_Count"].ToString());
                }
                if (row["FZRKY_Count"].ToString() != "")
                {
                    report.FZRKY_Count = int.Parse(row["FZRKY_Count"].ToString());
                }
                if (row["KY_Count"].ToString() != "")
                {
                    report.KY_Count = int.Parse(row["KY_Count"].ToString());
                }
                report.PayWay = row["PayWay"].ToString();
                if (row["BSY_Count"].ToString() != "")
                {
                    report.BSY_Count = int.Parse(row["BSY_Count"].ToString());
                }
                if (row["BDJ_Count"].ToString() != "")
                {
                    report.BDJ_Count = int.Parse(row["BDJ_Count"].ToString());
                }
                if (row["M_Count"].ToString() != "")
                {
                    report.M_Count = int.Parse(row["M_Count"].ToString());
                }
                if (row["S_Count"].ToString() != "")
                {
                    report.S_Count = int.Parse(row["S_Count"].ToString());
                }
                if (row["W_Count"].ToString() != "")
                {
                    report.W_Count = int.Parse(row["W_Count"].ToString());
                }
                if (row["M_ZTJ_Count"].ToString() != "")
                {
                    report.M_ZTJ_Count = int.Parse(row["M_ZTJ_Count"].ToString());
                }
                if (row["M_FTJ_Count"].ToString() != "")
                {
                    report.M_FTJ_Count = int.Parse(row["M_FTJ_Count"].ToString());
                }
                if (row["M_ZXJ_Count"].ToString() != "")
                {
                    report.M_ZXJ_Count = int.Parse(row["M_ZXJ_Count"].ToString());
                }
                if (row["M_FXJ_Count"].ToString() != "")
                {
                    report.M_FXJ_Count = int.Parse(row["M_FXJ_Count"].ToString());
                }
                if (row["M_ZKJ_Count"].ToString() != "")
                {
                    report.M_ZKJ_Count = int.Parse(row["M_ZKJ_Count"].ToString());
                }
                report.LevelName = row["LevelName"].ToString();
                if (row["M_FKJ_Count"].ToString() != "")
                {
                    report.M_FKJ_Count = int.Parse(row["M_FKJ_Count"].ToString());
                }
                if (row["M_KY_Count"].ToString() != "")
                {
                    report.M_KY_Count = int.Parse(row["M_KY_Count"].ToString());
                }
                if (row["M_BSY_Count"].ToString() != "")
                {
                    report.M_BSY_Count = int.Parse(row["M_BSY_Count"].ToString());
                }
                if (row["M_3"].ToString() != "")
                {
                    report.M_3 = int.Parse(row["M_3"].ToString());
                }
                if (row["M_4"].ToString() != "")
                {
                    report.M_4 = int.Parse(row["M_4"].ToString());
                }
                if (row["M_5"].ToString() != "")
                {
                    report.M_5 = int.Parse(row["M_5"].ToString());
                }
                if (row["M_6"].ToString() != "")
                {
                    report.M_6 = int.Parse(row["M_6"].ToString());
                }
                if (row["M_7"].ToString() != "")
                {
                    report.M_7 = int.Parse(row["M_7"].ToString());
                }
                if (row["M_8"].ToString() != "")
                {
                    report.M_8 = int.Parse(row["M_8"].ToString());
                }
                if (row["M_9"].ToString() != "")
                {
                    report.M_9 = int.Parse(row["M_9"].ToString());
                }
                if (row["UserBuild_Count"].ToString() != "")
                {
                    report.UserBuild_Count = int.Parse(row["UserBuild_Count"].ToString());
                }
                if (row["M_10"].ToString() != "")
                {
                    report.M_10 = int.Parse(row["M_10"].ToString());
                }
                if (row["S_ZGJ_Count"].ToString() != "")
                {
                    report.S_ZGJ_Count = int.Parse(row["S_ZGJ_Count"].ToString());
                }
                if (row["S_FGJ_Count"].ToString() != "")
                {
                    report.S_FGJ_Count = int.Parse(row["S_FGJ_Count"].ToString());
                }
                if (row["S_ZJ_Count"].ToString() != "")
                {
                    report.S_ZJ_Count = int.Parse(row["S_ZJ_Count"].ToString());
                }
                if (row["S_CJ_Count"].ToString() != "")
                {
                    report.S_CJ_Count = int.Parse(row["S_CJ_Count"].ToString());
                }
                if (row["S_1"].ToString() != "")
                {
                    report.S_1 = int.Parse(row["S_1"].ToString());
                }
                if (row["S_2"].ToString() != "")
                {
                    report.S_2 = int.Parse(row["S_2"].ToString());
                }
                if (row["S_3"].ToString() != "")
                {
                    report.S_3 = int.Parse(row["S_3"].ToString());
                }
                if (row["S_4"].ToString() != "")
                {
                    report.S_4 = int.Parse(row["S_4"].ToString());
                }
                if (row["S_5"].ToString() != "")
                {
                    report.S_5 = int.Parse(row["S_5"].ToString());
                }
                if (row["UserJobPostion_Count"].ToString() != "")
                {
                    report.UserJobPostion_Count = int.Parse(row["UserJobPostion_Count"].ToString());
                }
                if (row["S_6"].ToString() != "")
                {
                    report.S_6 = int.Parse(row["S_6"].ToString());
                }
                if (row["S_7"].ToString() != "")
                {
                    report.S_7 = int.Parse(row["S_7"].ToString());
                }
                if (row["S_8"].ToString() != "")
                {
                    report.S_8 = int.Parse(row["S_8"].ToString());
                }
                if (row["S_9"].ToString() != "")
                {
                    report.S_9 = int.Parse(row["S_9"].ToString());
                }
                if (row["S_10"].ToString() != "")
                {
                    report.S_10 = int.Parse(row["S_10"].ToString());
                }
                if (row["S_11"].ToString() != "")
                {
                    report.S_11 = int.Parse(row["S_11"].ToString());
                }
                if (row["S_12"].ToString() != "")
                {
                    report.S_12 = int.Parse(row["S_12"].ToString());
                }
                if (row["S_13"].ToString() != "")
                {
                    report.S_13 = int.Parse(row["S_13"].ToString());
                }
                if (row["W_GJJS_Count"].ToString() != "")
                {
                    report.W_GJJS_Count = int.Parse(row["W_GJJS_Count"].ToString());
                }
                if (row["W_JS_Count"].ToString() != "")
                {
                    report.W_JS_Count = int.Parse(row["W_JS_Count"].ToString());
                }
                if (row["Manager_Count"].ToString() != "")
                {
                    report.Manager_Count = int.Parse(row["Manager_Count"].ToString());
                }
                if (row["W_GJG_Count"].ToString() != "")
                {
                    report.W_GJG_Count = int.Parse(row["W_GJG_Count"].ToString());
                }
                if (row["W_ZJG_Count"].ToString() != "")
                {
                    report.W_ZJG_Count = int.Parse(row["W_ZJG_Count"].ToString());
                }
                if (row["W_CJG_Count"].ToString() != "")
                {
                    report.W_CJG_Count = int.Parse(row["W_CJG_Count"].ToString());
                }
                if (row["W_PTG_Count"].ToString() != "")
                {
                    report.W_PTG_Count = int.Parse(row["W_PTG_Count"].ToString());
                }
                if (row["W_0"].ToString() != "")
                {
                    report.W_0 = int.Parse(row["W_0"].ToString());
                }
                if (row["W_1"].ToString() != "")
                {
                    report.W_1 = int.Parse(row["W_1"].ToString());
                }
                if (row["W_2"].ToString() != "")
                {
                    report.W_2 = int.Parse(row["W_2"].ToString());
                }
                if (row["W_3"].ToString() != "")
                {
                    report.W_3 = int.Parse(row["W_3"].ToString());
                }
                if (row["W_4"].ToString() != "")
                {
                    report.W_4 = int.Parse(row["W_4"].ToString());
                }
                if (row["W_5"].ToString() != "")
                {
                    report.W_5 = int.Parse(row["W_5"].ToString());
                }
                if (row["Skiller_Count"].ToString() != "")
                {
                    report.Skiller_Count = int.Parse(row["Skiller_Count"].ToString());
                }
                report.Remark = row["Remark"].ToString();
                if (row["Worker_Count"].ToString() != "")
                {
                    report.Worker_Count = int.Parse(row["Worker_Count"].ToString());
                }
                return report;
            }
            return null;
        }
    }
}

